x86 hvm: Introduce pmtimer_change_ioport and HVM_PARAM_ACPI_IOPORTS_LOCATION
authorKeir Fraser <keir@xen.org>
Fri, 29 Oct 2010 17:42:34 +0000 (18:42 +0100)
committerKeir Fraser <keir@xen.org>
Fri, 29 Oct 2010 17:42:34 +0000 (18:42 +0100)
By default, Xen will handle the old ACPI IO port. But it can switch to
the new one by setting the HVM_PARAM_ACPI_IOPORTS_LOCATION to 1.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Keir Fraser <keir@xen.org>
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/intercept.c
xen/arch/x86/hvm/pmtimer.c
xen/include/asm-x86/hvm/io.h
xen/include/asm-x86/hvm/vpt.h
xen/include/public/hvm/ioreq.h
xen/include/public/hvm/params.h

index 472df2f82e1fcbcce44aaaa5fe42ef36a3f4ba00..45afb530d60852e9b2c9bda579b79b8d6e448929 100644 (file)
@@ -2991,6 +2991,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg)
                     rc = -EINVAL;
 
                 break;
+            case HVM_PARAM_ACPI_IOPORTS_LOCATION:
+                rc = pmtimer_change_ioport(d, a.value);
+                break;
             }
 
             if ( rc == 0 )
index 2d88cc86b02882d8b219421266221a5bc240644c..6ce49b6ad811f9d623edfd5d4f87cabad2948f81 100644 (file)
@@ -241,24 +241,18 @@ void register_io_handler(
     handler->num_slot++;
 }
 
-void unregister_io_handler(
-    struct domain *d, unsigned long addr, unsigned long size, int type)
+void relocate_io_handler(
+    struct domain *d, unsigned long old_addr, unsigned long new_addr,
+    unsigned long size, int type)
 {
     struct hvm_io_handler *handler = &d->arch.hvm_domain.io_handler;
     int i;
 
     for ( i = 0; i < handler->num_slot; i++ )
-        if ( (handler->hdl_list[i].addr == addr) &&
+        if ( (handler->hdl_list[i].addr == old_addr) &&
              (handler->hdl_list[i].size == size) &&
              (handler->hdl_list[i].type == type) )
-            goto found;
-    return;
-
- found:
-    memcpy(&handler->hdl_list[i],
-           &handler->hdl_list[handler->num_slot-1],
-           sizeof(struct io_handler));
-    handler->num_slot--;
+            handler->hdl_list[i].addr = new_addr;
 }
 
 /*
index 1b9ab7ba18fad02c5bd182e9e44d64e32cafbce7..4e8c98d3572036ac3267f1cf2f3886aecdbf65b6 100644 (file)
 #include <asm/hvm/io.h>
 #include <asm/hvm/support.h>
 #include <asm/acpi.h> /* for hvm_acpi_power_button prototype */
+#include <public/hvm/params.h>
 
 /* Slightly more readable port I/O addresses for the registers we intercept */
+#define PM1a_STS_ADDR_OLD (ACPI_PM1A_EVT_BLK_ADDRESS_OLD)
+#define PM1a_EN_ADDR_OLD  (ACPI_PM1A_EVT_BLK_ADDRESS_OLD + 2)
+#define TMR_VAL_ADDR_OLD  (ACPI_PM_TMR_BLK_ADDRESS_OLD)
 #define PM1a_STS_ADDR (ACPI_PM1A_EVT_BLK_ADDRESS)
 #define PM1a_EN_ADDR  (ACPI_PM1A_EVT_BLK_ADDRESS + 2)
 #define TMR_VAL_ADDR  (ACPI_PM_TMR_BLK_ADDRESS)
@@ -155,16 +159,20 @@ static int handle_evt_io(
             switch ( addr )
             {
                 /* PM1a_STS register bits are write-to-clear */
+            case PM1a_STS_ADDR_OLD:
             case PM1a_STS_ADDR:
                 s->pm.pm1a_sts &= ~byte;
                 break;
+            case PM1a_STS_ADDR_OLD + 1:
             case PM1a_STS_ADDR + 1:
                 s->pm.pm1a_sts &= ~(byte << 8);
                 break;
                 
+            case PM1a_EN_ADDR_OLD:
             case PM1a_EN_ADDR:
                 s->pm.pm1a_en = (s->pm.pm1a_en & 0xff00) | byte;
                 break;
+            case PM1a_EN_ADDR_OLD + 1:
             case PM1a_EN_ADDR + 1:
                 s->pm.pm1a_en = (s->pm.pm1a_en & 0xff) | (byte << 8);
                 break;
@@ -272,6 +280,35 @@ static int pmtimer_load(struct domain *d, hvm_domain_context_t *h)
 HVM_REGISTER_SAVE_RESTORE(PMTIMER, pmtimer_save, pmtimer_load, 
                           1, HVMSR_PER_DOM);
 
+int pmtimer_change_ioport(struct domain *d, unsigned int version)
+{
+    unsigned int old_version;
+
+    /* Check that version is changing. */
+    old_version = d->arch.hvm_domain.params[HVM_PARAM_ACPI_IOPORTS_LOCATION];
+    if ( version == old_version )
+        return 0;
+
+    /* Only allow changes between versions 0 and 1. */
+    if ( (version ^ old_version) != 1 )
+        return -EINVAL;
+
+    if ( version == 1 )
+    {
+        /* Moving from version 0 to version 1. */
+        relocate_portio_handler(d, TMR_VAL_ADDR_OLD, TMR_VAL_ADDR, 4);
+        relocate_portio_handler(d, PM1a_STS_ADDR_OLD, PM1a_STS_ADDR, 4);
+    }
+    else
+    {
+        /* Moving from version 1 to version 0. */
+        relocate_portio_handler(d, TMR_VAL_ADDR, TMR_VAL_ADDR_OLD, 4);
+        relocate_portio_handler(d, PM1a_STS_ADDR, PM1a_STS_ADDR_OLD, 4);
+    }
+
+    return 0;
+}
+
 void pmtimer_init(struct vcpu *v)
 {
     PMTState *s = &v->domain->arch.hvm_domain.pl_time.vpmt;
@@ -284,8 +321,8 @@ void pmtimer_init(struct vcpu *v)
 
     /* Intercept port I/O (need two handlers because PM1a_CNT is between
      * PM1a_EN and TMR_VAL and is handled by qemu) */
-    register_portio_handler(v->domain, TMR_VAL_ADDR, 4, handle_pmt_io);
-    register_portio_handler(v->domain, PM1a_STS_ADDR, 4, handle_evt_io);
+    register_portio_handler(v->domain, TMR_VAL_ADDR_OLD, 4, handle_pmt_io);
+    register_portio_handler(v->domain, PM1a_STS_ADDR_OLD, 4, handle_evt_io);
 
     /* Set up callback to fire SCIs when the MSB of TMR_VAL changes */
     init_timer(&s->timer, pmt_timer_callback, s, v->processor);
index 8a81bff225f24ce50a072220c93cf202e5e0bd77..fe2ecdad0e47167fb59a75c0d09fe7da49b94434 100644 (file)
@@ -69,8 +69,9 @@ int hvm_io_intercept(ioreq_t *p, int type);
 void register_io_handler(
     struct domain *d, unsigned long addr, unsigned long size,
     void *action, int type);
-void unregister_io_handler(
-    struct domain *d, unsigned long addr, unsigned long size, int type);
+void relocate_io_handler(
+    struct domain *d, unsigned long old_addr, unsigned long new_addr,
+    unsigned long size, int type);
 
 static inline int hvm_portio_intercept(ioreq_t *p)
 {
@@ -92,10 +93,11 @@ static inline void register_portio_handler(
     register_io_handler(d, addr, size, action, HVM_PORTIO);
 }
 
-static inline void unregister_portio_handler(
-    struct domain *d, unsigned long addr, unsigned long size)
+static inline void relocate_portio_handler(
+    struct domain *d, unsigned long old_addr, unsigned long new_addr,
+    unsigned long size)
 {
-    unregister_io_handler(d, addr, size, HVM_PORTIO);
+    relocate_io_handler(d, old_addr, new_addr, size, HVM_PORTIO);
 }
 
 static inline void register_buffered_io_handler(
index 65b0dffb98d2bd998c84adfcfeb9794d6f426ea8..0fe8dbfd7e076cb9a0cbb9e0f4cf193541e07246 100644 (file)
@@ -179,6 +179,7 @@ void rtc_update_clock(struct domain *d);
 void pmtimer_init(struct vcpu *v);
 void pmtimer_deinit(struct domain *d);
 void pmtimer_reset(struct domain *d);
+int pmtimer_change_ioport(struct domain *d, unsigned int version);
 
 void hpet_init(struct vcpu *v);
 void hpet_deinit(struct domain *d);
index 0c10c08a6dc4dfac5d03ca59d4e8b3271949aabd..9b67bf09c5f056857eeeee1908c3882f7e4c97e7 100644 (file)
@@ -100,11 +100,21 @@ struct buffered_piopage {
 };
 #endif /* defined(__ia64__) */
 
-#define ACPI_PM1A_EVT_BLK_ADDRESS           0x0000000000001f40
-#define ACPI_PM1A_CNT_BLK_ADDRESS           (ACPI_PM1A_EVT_BLK_ADDRESS + 0x04)
-#define ACPI_PM_TMR_BLK_ADDRESS             (ACPI_PM1A_EVT_BLK_ADDRESS + 0x08)
-#define ACPI_GPE0_BLK_ADDRESS               (ACPI_PM_TMR_BLK_ADDRESS + 0x20)
-#define ACPI_GPE0_BLK_LEN                   0x08
+/*
+ * Value used by old qemu-dm, there have been replace to match
+ * the QEMU BIOS.
+ */
+#define ACPI_PM1A_EVT_BLK_ADDRESS_OLD 0x1f40
+#define ACPI_PM1A_CNT_BLK_ADDRESS_OLD (ACPI_PM1A_EVT_BLK_ADDRESS_OLD + 0x04)
+#define ACPI_PM_TMR_BLK_ADDRESS_OLD   (ACPI_PM1A_EVT_BLK_ADDRESS_OLD + 0x08)
+#define ACPI_GPE0_BLK_ADDRESS_OLD     (ACPI_PM_TMR_BLK_ADDRESS_OLD + 0x20)
+#define ACPI_GPE0_BLK_LEN_OLD         0x08
+
+#define ACPI_PM1A_EVT_BLK_ADDRESS     0xb000
+#define ACPI_PM1A_CNT_BLK_ADDRESS     (ACPI_PM1A_EVT_BLK_ADDRESS + 0x04)
+#define ACPI_PM_TMR_BLK_ADDRESS       (ACPI_PM1A_EVT_BLK_ADDRESS + 0x08)
+#define ACPI_GPE0_BLK_ADDRESS         0xafe0
+#define ACPI_GPE0_BLK_LEN             0x04
 
 #endif /* _IOREQ_H_ */
 
index 673148bbfa28ff7fc3e44a60cb0d439fad8baa6c..2359f33fe968709a97e3418a3948aada73a0106c 100644 (file)
 #define HVM_PARAM_CONSOLE_PFN    17
 #define HVM_PARAM_CONSOLE_EVTCHN 18
 
-#define HVM_NR_PARAMS          19
+/*
+ * Select location of ACPI PM1a and TMR control blocks. Currently two locations
+ * are supported, specified by version 0 or 1 in this parameter:
+ *   - 0: default, use the old addresses
+ *        PM1A_EVT == 0x1f40; PM1A_CNT == 0x1f44; PM_TMR == 0x1f48
+ *   - 1: use the new default qemu addresses
+ *        PM1A_EVT == 0xb000; PM1A_CNT == 0xb004; PM_TMR == 0xb008
+ * You can find these address definitions in <hvm/ioreq.h>
+ */
+#define HVM_PARAM_ACPI_IOPORTS_LOCATION 19
+
+#define HVM_NR_PARAMS          20
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */